package ex.mlist;




import Database.DBHelper;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.Toast;

public class Changetone extends Activity{
	private AlertDialog.Builder builder;
	private AlertDialog alert;
	String name;
	int set;
	int size;
	
	DBHelper db;
	Bundle b;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.main);
		 b=getIntent().getExtras();
		
		set=b.getInt("settone");
		int profile=b.getInt("profile_id");
		set(profile);
		
	}
	
	
	public void set(int profile)
	{
		SharedPreferences tones = getSharedPreferences("MYLIST", 0);
	    SharedPreferences.Editor editor=tones.edit();
	    int profile_id=tones.getInt("profile_id",1);
	    
	    if(profile==profile_id)
	    {
	    editor.putInt("set", set);
	    editor.commit();
	    if(set==1)
	    {
	    	name=b.getString("ringtone_src");
	    	size=b.getInt("size");
	    	change_tone();
	    	
	    }
	    
	    }
	    
	}
	
	public void change_tone()
	{
		ContentValues values = new ContentValues();

		values.put(MediaStore.MediaColumns.DATA,"/"+name);
		values.put(MediaStore.MediaColumns.TITLE,name);
		values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg");
		values.put(MediaStore.MediaColumns.SIZE, size);
		values.put(MediaStore.Audio.Media.ARTIST, "Artist");
		values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
		values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
		values.put(MediaStore.Audio.Media.IS_ALARM, false);
		values.put(MediaStore.Audio.Media.IS_MUSIC, false);

		Uri uri = MediaStore.Audio.Media.getContentUriForPath("/"
				+ name);
		Uri newUri = getContentResolver().insert(uri, values);

		RingtoneManager.setActualDefaultRingtoneUri(Changetone.this,
				RingtoneManager.TYPE_RINGTONE, newUri);
	}
		
}

